﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SocialLearning
{
    public partial class RoleNewForm : Form
    {
        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="GroupNewForm"/> class.
        /// </summary>
        public RoleNewForm()
        {
            InitializeComponent();
        }

        #endregion

        #region Private Methods

        /// <summary>
        /// Handles the Load event of the UserForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void UserForm_Load(object sender, EventArgs e)
        {
            LoadCbxData();
        }

        /// <summary>
        /// Loads the CBX data.
        /// </summary>
        private void LoadCbxData()
        {
            foreach (string groupname in UAC_GroupManagement.Instance.SeeGroup())
            {
                cbxGroup.Items.Add(groupname);
            }

            foreach (var user in UAC_UserManagement.userlist)
            {
                cbxUser.Items.Add(string.Format("{0} {1}", user.BasicAccountDetails.Firstname, user.BasicAccountDetails.Lastname));
            }
        }

        #endregion

        #region Private Controls

        /// <summary>
        /// Handles the Click event of the btnCreate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(cbxGroup.Text) || string.IsNullOrWhiteSpace(cbxUser.Text))
                MessageBox.Show("Please enter a user and group name", "Information",
                       MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                if (UAC_GroupManagement.Instance.AddMember(cbxGroup.Text, UAC_UserManagement.userlist[cbxUser.SelectedIndex].BasicAccountDetails.ID))
                {
                    MessageBox.Show("User is added to the group", "Information",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cbxGroup.Text = "";
                    cbxUser.Text = "";
                }
                else
                    MessageBox.Show("User is not added to the group", "Information",
                   MessageBoxButtons.OK, MessageBoxIcon.Information);



            }
        }

        /// <summary>
        /// Handles the Click event of the btnCancel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}
